<?php

namespace backend\controllers;

use bc\controller\BackendController;
use bc\model\PlatoModel;
use bc\util\backend\Page;

class PlatoController extends BackendController
{
	public function actionIndex()
	{
		$view = [ ];
		$model = new PlatoModel ();
		
		$params = '1 = 1';
		
		$page = $this->get ( 'page', 1 );
		$model->sort = 'job_count desc, play_date asc';
		$list = $model->getList ( $params, $page, self::PAGE_SIZE );
		
		$total = $model->getTotal ( $params );
		
		$pagination = new Page ( $total, self::PAGE_SIZE );
		
		$view ['list'] = $list;
		$view ['pagination'] = $pagination;
		
		return $this->render ( 'index', $view );
	}
	public function actionEdit()
	{
		$id = $this->get ( 'id' );
		if (! $id)
			$this->redirect ( '/' );
		
		$page = $this->get ( 'page', 1 );
		
		$model = new PlatoModel ();
		$row = $model->getRowById ( $id );
		
		if (! $row)
			$this->redirect ( '/' );
		
		$list = [ ];
		
		$activityModel = new ActivityModel ();
		$params ['baby_id'] = $row ['id'];
		
		$activityModel->sort = 'activity_id DESC';
		$list = $activityModel->getList ( $params, $page, self::PAGE_SIZE );
		$total = $activityModel->getTotal ( $params );
		
		$pagination = new Page ( $total, self::PAGE_SIZE );
		
		$view ['row'] = $row;
		$view ['list'] = $list;
		$view ['pagination'] = $pagination;
		$view ['jobs'] = $this->jobs;
		
		return $this->render ( 'edit', $view );
	}
}

